import java.io.IOException;

public class Leetcode404 {
    public static void main(String[] args) throws IOException {

    }

    public int findKthNumber(int n, int k) {
        int root = 1;
        while (k > 1) {
            long count = 0;
            long firstSon = root;
            long nextBrother = root + 1;
            while (firstSon <= n) {
                count += Math.min(n + 1, nextBrother) - firstSon;
                firstSon *= 10;
                nextBrother *= 10;
            }
            if (count <= k - 1) {
                root++;
                k -= count;
            } else {
                root *= 10;
                k--;
            }
        }
        return root;
    }
}
